Made some refactorings, unfinished