Simplify duplicate code