$prior_appeared is initially null which causes an error. Fixed.