added a mem leak protector