blech. 2 loops per output but this is definitely not the best.