fixed some bugs in calculating probability