add panTo method
reorganize the code