Modify for the latest leofs and refactor