             (when column
               (indent-to column))
             (skip-chars-backward " \n\t")
-            (setq end (point)))
+            (set-marker end (point)))
            (t          ;`end' is either at EOL or looking at trailing whitespace
             ))
           ;; Now delete the content in the selected region and save it to
           ;; `content'.
-          (setq content (delete-and-extract-region beg end)))
+          (setq content (delete-and-extract-region beg end))
+          ;; Make the `end' marker point to nothing as its job is done.
+          ;; http://lists.gnu.org/archive/html/emacs-orgmode/2017-09/msg00049.html
+          ;; (elisp) Overview of Markers
+          (set-marker end nil))
 
         ;; Insert the `str' required for template expansion (example: "<e").
         (insert str)
         (org-try-structure-completion)
-        (when (string= "<s" str)
+        (when (let* ((case-fold-search t)) ;Ignore case
+                (looking-back "^[[:blank:]]*#\\+BEGIN_SRC[[:blank:]]+"))
           (cond
-           (lang
+           ((stringp lang)
             (insert lang)
             (forward-line))
-           ((and content (not lang))
+           ((and (null lang)
+                 content)
             (setq post-src (point))
             (forward-line))
            (t

        ;; Now if a region was selected, and `content' was saved from that,
        ;; paste it back in.
        (when content
          ;; A special case for org source blocks.. need to escape "*" and "#+"
          ;; with commas -- (org) Literal examples.
          (when (string= "org" lang)
            (setq content (org-escape-code-in-string content)))
          (insert content)
          (deactivate-mark)

    ;; https://github.com/abo-abo/hydra/wiki/Org-mode-block-templates

    (defun modi/org-template-expand (str &optional lang)
      "Expand Org template based on STR.

STR is always prefixed with \"<\".  The string following that
\"<\" must match with the `car' of one of the elements in
`org-structure-template-alist' (examples: \"<e\", \"<s\").

If no region is selected, this function behaves like
`org-try-structure-completion' (See (org) Easy templates).  If a
region is selected, the selected text is wrapped with that org
template.

If the \"#+BEGIN_SRC\" block is inserted and LANG is a string,
that source block is annotated with that LANG.  Instead, if LANG
is nil, point is returned to the end of the \"#+BEGIN_SRC\" line
after the template insertion."
      (let* ((is-region? (use-region-p))
             (beg (if is-region?
                      (region-beginning)
