use array shift instead of pop