Bug fixes, cleanup and small optimization on getStartTag