I think adding a couple of println statements to the code so you can see what it is doing will help you figure out how to make it do what you want it to do.