improved snap to edge