Refactor function calls and parameter passing