Finished valmask sum function.