Added a function to clamp a number in between a certain range.