Refactoring for function call mechanism

This is a separated pull request from #1409, that contains refactoring changes only.