Improved comments and fixed minor bug.