Modified sample.cpp