added comments and fixed an error at line 534