added check for error variable