Simplified options processing and changed debug output to come out on stderr.