Moved the map drawing code into a function.