Refactor a lot, export directly to map.sqlite