Refactored map JS code.