merge recursive functions