significant refactorings and decrappification