Program now produces logically correct output. The output is still rough but the next update will smooth things out.