Ranging and other minor bug fixes. Comments added.