added comments and made slight formatting changes