Some much needed error checking.