serial version, changed k for sum vector.