router code logic cleanup