refactor function call