Improve tag parsing and fix the same crashing bug as before