Fix bug with undefined variable