working without recursive