improve error checking