added comment and error checking