Added error logging and exit on error