weighted mean stuff, skeleton pathfinding code