fixed clang complaining about C++11, and removed duplicated code