added comments + correct error reporting