Updated the SQL Functions