Remove trailing whitespace and "print url" lines.
More consistent error checking.
More improved logging.