Moved generic functions from database to crud.