added comments and fixed a couple bugs