keep in bounds and move reference when outside bounds