Cleaned up error checking.