Fixed possible NPE problems.