Refactor database code. Code cleanup.