Massive refactoring to use promises, rather than raw callbacks