code cleanup, added null check