             count_dot = 0
             num_not_open_parenthesis = 0
 
-            is_string = false
-            char_used = ''
             for i in [query.length-1..0] by -1
-                if is_string is false
-                    if (query[i] is '"' or query[i] is '\'')
-                        #is_string = true
-                        char_used = query[i]
-                    else if query[i] is '(' and num_not_open_parenthesis is 0
-                        num_not_open_parenthesis--
-                        end = i+1
-                    else if query[i] is '(' and num_not_open_parenthesis isnt 0
-                        return query.slice i+1, end
-                    else if query[i] is ')'
-                        return ''
-                    else if query[i] is '.' and num_not_open_parenthesis is 0
-                        return ''
-                    else if query[i] is '.' and num_not_open_parenthesis isnt 0
-                        return query.slice i+1, end
+                if query[i] is '(' and num_not_open_parenthesis >= 0
+                    num_not_open_parenthesis--
+                    end = i+1
+                else if query[i] is '(' and num_not_open_parenthesis < 0
+                    return query.slice i+1, end
+                else if query[i] is ')'
+                    num_not_open_parenthesis++
+                else if query[i] is '.' and num_not_open_parenthesis < 0
+                    return query.slice i+1, end
             if end?
                 return query.slice 0, end
 

                    if (query[i] is '"' or query[i] is '\'')
                        is_string = true
                        char_used = query[i]
                    else if query[i] is '('
                        num_not_open_parenthesis--
                    else if query[i] is ')'

            # Hack because last_function returns 'r' if the query is 'r'. and r isn't a function
            if last_function is query and last_function is 'r'
                last_function = ''

            if @map_state[last_function]? and @suggestions[@map_state[last_function]]?
                if not @suggestions[@map_state[last_function]]? or @suggestions[@map_state[last_function]].length is 0 or just_description is true
                    @hide_suggestion()
