Add globalMax support. Change sum reduction loop slightly.