fix routing algorithm