refactor with closure