refactor database code to handle both enviroments