Problem #3 reworked to be massively more efficient