more comments and error checking