Cleaned the code, added notes