Fixed some some potential problems.

Please do not delete the branch.