Cleanup in ML algorithms inside commons, changed logic in PGMEM