brute force, but should be easy to optimize