minor refactoring to avoid possible NPE.