Flatten arguments to functions

Close #4320