major refactoring for mixed leaf device, WIP, DONOT use for QA