added some != null cjecks