Remove some dead code, refactor