Add programmer's guide, refactor a few places.