One quick way to understand what code is doing is to write a program that executes it and look at the results.
Separate the code into separate method calls and print out the results for each call.
...