Problem 4. Could be faster, but good enough.