Factorised some code in the database manager