updated function to work with new database