create outer function for comparison and fix simulate bug