Fully functional working code