implemented #7. it isn't fast, or clever, but it gets there.