Refactoring the code for helping #65 and fixing #70.

The changes by this pull request must be validated by the other developers.

<!---
@huboard:{"order":71.0,"milestone_order":71.0,"custom_state":""}
-->