fixed some arithmatic calculations bugs