Clean up some of the map JS, reduce scope of globals