Improve basic error checking