implementation for feature for closing and opening all markers in  a document (as per issue #10).
Also include some minor refacotring