Latest fully working code