Many corrections and refactorings