ported to py3k, fixed minor typos