Refactoring for GCC 4.8 and C++11

This pull request removes all warnings and errors happening on the above environment.
No change in code meanings, just refactoring.

If you don't like the "large refactoring" (as I removed all trailing spaces), you can consider to just cherry-pick the commit `47824ad791ee36c874212a48207b026f36c48437`.