changed: added null checks in some functions