Added printError function. Also new error checks