Small changes

Fix warnings, use range-based loops where possible, and some things suggested by cppcheck.