added a debug option and exit, also fixed another small issue