Rescue from mysql errors, Code Cleanup