Minor refactoring to use try-with-resources and better map-building