fix tags not being preserved, fix lingering empty nodes