corrected recursive function testing condition and store input data