Made some changes and added some comments