Refactored to make use of existing mapping infrastructure and simplified overall structure according to Michael's input.