Add comments and code style fix for the while file
Merge pull request #2235 from RoyXue/faster_algo

Add comments and code style fix