fixed bug in character matrix calculation