fixed math bugs