Remove old code and more refactoring