Some improvements fixing NPE