Use scoped_ptr to manage memory instead of allocating everything on the stack