Removing unnecessary $.when