added explanatory comments
added more comments and removed error messages