working code with changes