added mapping capability, revamped part of the code to get cleaner, more efficient code