refactor execute function