Code Optimizations/Cleanup of Database functions