refactor to remove undefined variable