remove unreachable code
fix a few wrong variable names
Fix some typos detected by static analyzer