much porting of matlab code, in progress