added null checks on creating and updating