Some cleanup; also fixed the brokenness of the curve by adding a minimum and maximum limit to the values