Code cleanups and removal of dead code