Small fixes

Bugs:
The library throws an error when injecting an element at the very end of a text node. 
The library returns invalid textnode index when generating text node cfis.