Improved comments and fixed some bugs