changes from upstrean + changes from tesseract's branch (phew)