Modified to use std::functional

Sorry, Sam - couldn't resist ;)