updated router code to make more sense