Simplify some code

Separate invalid tags and error status processing.

Signed-off-by: leo-ma <begeekmyfriend@gmail.com>