Refactor error handeling flow throughout library