(2) sync whitespaces, (3) update comments. (4) bring in some of portability and logging enhancements. no functional changes here.
NOTE: this branch (kame) is used just for refernce. this may not compile due to multiple reasons.