Fix issues with database functions