Refactor code using CPP