Refactoring in snapping code