Updated for c++11
Merged with some changes