re-construct the codes following the template method pattern.