Added a test_program function and generally rewrote the whole thing...