Minor factoring. Documentation added.