Reorganize and cleanup code.
- consistent ordering
- lots more comments
- whitespace fixups

Cleanup part 2. More comments and reordering.
Simplify code using new reactive 'ready' function on subscription handles.
Remove unused requires.
Oops, missed a spot.
Comment on issue #828
Merge branch 'code-cleanup' into devel