Refactor latex execution