             asToBeClosed--
           else
             splitText[index] = ""
-        else if s.substring(0,3) == "/if"
-          if spansToBeClosed > 0
-            splitText[index] = "</span>"
-            spansToBeClosed--
-          else
-            splitText[index] = ""
         index++
+      # Join all back into a string
       text = splitText.join("")
       return text
 

            spansToBeClosed++
          else
            splitText[index] = ""
        else if s.substring(0,5) == "stat."
          value = s.substring(5,s.length)
          for i in data.game.stats
            if i.name == value
              splitText[index] = i.value
        else if s.substring(0,4) == "inv."
          value = s.substring(4,s.length)
          for i in data.game.inventory
            if i.name == value
              splitText[index] = i.count
        else if s.substring(0,5) == "print"
          parsed = s.split("print ")
          splitText[index] = @parseStatement(parsed[1])
        else if s.substring(0,5) == "input"
          parsed = s.split("input ")
          nameText = ""

  # Parse a text for Novel.js tags, and replace them with the correct HTML tags.
  parseText: (text) ->
    if text != undefined
      # [s] tags
      for i in [0 .. 99]
        text = text.split("[s" + i + "]").join("<span class=\"highlight-" + i + "\">")
      text = text.split("[/s]").join("</span>")
      # Other tags
      splitText = text.split(/\[|\]/)
      spansToBeClosed = 0
      asToBeClosed = 0
      for index in [0 .. splitText.length-1]
        s = splitText[index]
        # [if] statements
        if s.substring(0,2) == "if"
          parsed = s.split("if ")
          if !@parseStatement(parsed[1])
