extensive commenting. minor bug fixes