add more output and error checking, also some comments