algorithm is finally working; fixing some breaking issues with different zoom levels