Reorganized the code for simpler hacking. Improved architecture document.