added debugging code to REST methods and --debug option to command line