Broken, refactoring from scratch. Le sigh.