Don't call std::next and dereference twice in the inner loop and fix formatting of brace