added comments throughout the code