Conversion to promises and general cleanup.