Went thorough the code and added some comments