router code cleaned up