more thorough checking to avoid NPEs
formatting