Added validation and cleanup for cryptographically secure state token functionality