inserted all of HY's original code and some comments