Convert to std::make_shared() to avoid allocation overhead

This also tidies up the code in main() in a way that doesn't make it
susceptible to memory leaks.