solve segmentation fault in end_purchase