Further major rewrite