Form a template method to rid duplicated codes