Rewrote the snap_value function to be more readable.

Functionality should not change.