fixed incorrectly handled error check