Refactor the panning code into separate functions, and correct a comment