added comment block describing algorithm