Cleaned the code and made some comments