note for better algorithm for determining whether to insert <% end %>