Moved database operations to own methods