Some clean up and math fixing based on suggestions from AceFanatic02