massive changes to functions