Move path calculate logic to function.