improve error check