re-applied changes from https://github.com/jskda/nltk/commit/06d75ceaec1c561d5d5548b597db6e6bb26eb0a3, cf https://github.com/nltk/nltk/issues/670