Added error logging into logfile