Fixed some run-time errors. Algorithm is currently entering an infinite loop. Needs further investigation.