rec function fixed