refactored maps code and used scopes