Fixed an error and added a few comments