cleaned up average calc code, still need to debug relation add nonsense