optimized panning function