Add potentially missing include, add check and use unique_ptr when in c++11