Added inline comments and some doc on common subfunctions.