Remove legacy cruft and migrate core code to mainline