fix/improve error catching