Updated the prototype. Almost ready to use as working code.