Moved work with the database to an external class.