refactor codes for computing OCR