Porting code from MatLab - performance improvement tricks

(topic deleted by author)