Error logging and more error checking.