added part median and fixed some other parts. Also synched templateMALength of Java with MATLAB