better panning code