Rewritten from scratch.