remove unneeded sum, add max function to R