Refactor with promises