Translated and refactored up to line 1255
further Translation and refactoring