fixed bug in spacing calculation