Corrected and working code