replace while() with easier to read for() loop, reduce count of local variables, reduce count of get() calls.