Add auto-checking.
Fix memory management