corrected some errors to improve calculations