Revised next so that it is recursive