added commen and fixed some bugs.