Massive documentation overhaul and some related code tweaks.