Rewrite purchase date finding code