ml and other refactoring