A useful pattern to replace ugly callbacks with promises