Reformatting, logic improvements, tests with junit and antunit, general cleanup.