Bug fixes for database functions - all db functions should be working