Improve the error handling for custom tags to ensure that the tag is returned to the pool or released and destroyed once used.