removed unnecessary code and added more comments