many changes. templates inline. copious comments.