Address come comments.

Add more comments, improved the compliance to the Google C++ style guide, and
added more CHECKs, for safety.