Added credit for borrowed code and introductory comment describing function.