Refactoring auto_arg for efficiency and referential transparency