added check for result == error