Corrected a lot of problems after the refactoring