SQL functions added and improved