clean up and factor out maxDistance into config as well