added piping and error handling