Several improvements and refactorings Iteration 3