refactor database.rb