Fix convert-to-map

- Better implementation of convert-to-map
- Add unit test for convert-to-map