Simplify the code by using some private method to substitute the replicate code