better logic for referer