Refactorings and removal of unused code