Minor restructuring. Bugs fixed. Release candidate.