minor fixes

moved initialization outside the loop and code alignment