Make memory efficient & Rewrite in C++11