Changed: avoid unnecessary checks
Fixed: several memory leaks found