Breaking up nested logic into promises