Fixed compile errors with c++11 compiler.
Changed to use 'auto' as many as possible.