moving map code to core/map + refactoring