My initial code
After shyam changes