Fixing NPE at instance termination