Improved snap logic. See Commons #2779