added some documentation and minor reformatting