refactor with jquery promisses