Working on main recursive function