Made some cleanup (dead code) and small optimizations