Fixing NPE when calling clear