Fixed a bug on the last commit that does not check the closest slot to snap to.