working code used for the challenge