fixing code, adding comments