Fixed the logic for incorrect zooming and added more descriptive comments.