Cleaning the code, adding comments