Fixed bugs when zooming in
cleaned up code