reworking logic for 2D clamping