changed to max instead of avg and use double instead of int