added code to hopefully redirect errors to a log file