Not the most elegant, but runs in about 0.6 seconds