slightly better error handling and behavior when invoked as a module.