More refactoring and removal of unnecessary code.