Fixed misc bugs found when review with David.