Added more comments to clarify bits of code.