Moved some functions to models/database.php