Added error flag to handle pipes more correctly