implemented min_first_loop and simplified