added comment
added max iterations check
improved comments
improved readability