localize variables and fix style