Remove some dead code + minor refactorings