Code Cleanup and misc