works, but terribly inefficient
more efficient