finished rules algorithm