fixed bug in calculations