incorporate @rhapsodhy's corrections and some further corrections