rewriting the route function to be #better and more #complete