modified template.cpp. add REP