Removing warnings, dead code, duplication and few bugs

Few commits with lots of random things, Clumped into PR for greater reviewing pleasure.

Also: pointless style changes!