commented main loop
reordered functions in java file