working code for required