Fixed problems from code review except for renaming.