first cut; space inefficient
more space efficient