Refactor map.dart and add tests