Refactor of mapping script and add docs