Code Cleanup and minor fix