modified working code