cleaned up use of accumulator in substitution function, use thins accumulator in closure