Refactor function call generation