Complete working code