added some comments and removed some unnecessary lines of code