Promised functions are working now in the right order