refactor, add fault tolerance