[incomplete] hard refactoring and porting to M3