leaf refactor working