Merge development back in master

Merging code refactored by @francesco-romano . 
@EnricoMingo  I think is better to merge it before you start working on the code. It is ok for you?