fixed error handling (but really this time)