Get rid of unnecessary extra arguments to lambda
Less mallocs by getting rid of std::function