Fault tolerance implemented and code cleaned up