working code trial and tested