Broken it. Starting major rewrite.