updated calculations and error checking.