Modified nearly everything to support promises.