Forward and rejection sampling, plus other cleanup.