Modify for latest leofs and refactor