refactor refund code