Remove unused assigns
Remove constant values in conditions and fix potential NPEs
Remove unused imports
Merge pull request #998 from dlsniper/fix-906

Code cleanup [fixes #906]