Refactored database code.