Modified to make use of some C++11 features.