java: refactoring - variables definistion moved out of loops, added final modifier to mark unchangable variables