copied working code.