Function refactor