Modified to use std::functional