changed printf to fprintf in error condition, now outputs to stderr