Full working code