Refactoring evolutions

Removed duplication from codes, extracted some methods and fixed scaladoc comments.