adds some comments and error checking