fixing logic to check null