Algorithm is way too slow.