Added/wrote up test classes, fixed up setflag/testflag to ensure they passed the tests, and reorganized main program code to be in understandable methods.