 	  ;; vars inside of the function
 	  (when (and begin-function end-function)
 	    (goto-char begin-function)
-	    (while (re-search-forward *ojs-vars-regexp* (min (point-max) end-function) t)	      
+	    (while (re-search-forward *ojs-vars-regexp* end-function t)	      
 	      (if list-of-cons
 		  (push (cons (match-string-no-properties 1) (match-string-no-properties 0)) vars)
 		(push (match-string-no-properties 1) vars)))

		    (or (er--point-is-in-comment-p)
			(er--point-is-in-string-p)))
	  (setq last-point found-point)
	  (setq found-point (re-search-forward regexp (min (point-max) limit) errorp)))
	found-point))
  (re-search-forward regexp (min (point-max) limit) errorp))

(defun start-of-function ()
  ;; get the start of the function

  (if *use-real-search*
      (let ((last-point (point))
	    ;; do a first search
	    (found-point (re-search-backward regexp limit errorp)))
	;; checks that we are moving to avoid loops
	(while (and found-point
		    (< (point) last-point)
		    (or (er--point-is-in-comment-p)
			(er--point-is-in-string-p)))
	  (setq last-point found-point)
	  (setq found-point (re-search-backward regexp limit errorp)))
	found-point))
  (re-search-backward regexp limit errorp))

