Important change :
main func is split to many main_stat func
to make it better suit for matlab