fixed bug with calculations