Clean up with some lexical scoping