Move zoom level updating logic to its own function and add tests