added more commenting and clarity