Refactored snapping.