Cleaning and commenting the code