moved tag parsing into separate function