I think this is a pretty generic parsing function, so we should probably not put it here, but in a global api