multiple enhancements, functions redefined, added doc, corrected indent