Fix dynamically overriding autocommand calls
Move useless globals into locals