added comments and fixed a bug
added comments