Code Cleanup and fix issues