Refactor forest writing code into forestwriter object
Clean up and docs