Some minor optimizations and stricter validation.