Refactored map js