Fixed some pipeline failure handling and added more unit tests