modified the function for database