full solution, too slow