The distribution of Hardy's function $Z(t)$ and the argument function $S(t)$