refactoring mapController and adding unit tests.