working version of routing which is not too slow