Improve parsing algorithm [add end tag handling]