Fixed some bugs after comparing known good output with programs output.