Bugfix: correctly snap to upper bound