Added several functions for advanced DB queries