refactor locals, pull literals out of loop