Refactor integer clipping function