fix compile on osx
fix variable shadowing
avoid copies / constness / c++11 for loops