Several improvements and refactorings Iteration 4