Refactor database class.