Fix some warnings
Turn loops into range-based form

and some things suggested by cppcheck and compiler warnings.
Merge pull request #65 from Tilka/nits

Small changes