Fixing nil check to test pointer instead fo value