cleaned up comments and added wait loops