compile using g++ -std=c++0x -pthread refactored.cpp