flattened promise nesting, by using additional functions