moved expandFrontier inside findPath, because it's unlikely to be used in other contexts