Another version of keepPosition - based on average distance. Also fixed a bug in first version (when compounding distance between agents)