added comments and fixed some small errors