fixed bug with promises