Cleaning up code and making it async.