simplify code with generalisation of function of record child