Code corrected and improved, ready for classification