modified code to use maps