Fixed clamping function to use reflection.