refactored code to be more c++11'y.