Improved geocoding function

Fixes #212, fixes #228