working, but still brute force and no optimization.