First rewrite from mapbox cpp source