Merge dev into master

A lot of new features and bug fix, mostly focused at the Matlab code.