Restructured main() a little and removed debug text output.