Rewrote code to use promises.