cleanup memory handling to use boost::scoped_ptr instead of manual deletion of stuff