Fix obvious warnings and remove dead code