Two loops would be cleaner...