change names, use array to store checkeda and improve conditions