Adding the latest working code