working version upto APE calulation for MC