Fixed serialization order for tags, added tests