Switched some loops to range-based for readability and performance

Also reintroduced locking into the Log class