Fixups to get things working better with older Python

Also, use replace_handler, duh.