start and end loop functions