Would it be possible to make this a separate method? It's getting really much code here and the need of assigning all variables to null and -1 would disappear. Would also make it a bit more clear what the code does.