Moved database functionality to its own module.