fixed problem. Solves it correctly, but terribly slow.