Error catching improved