Change argument positions in function copy
Add permission set in function copy
Add  test case of multiple calls of flush