Major refactor to use promises.