pretty much cleaned up, and working stably so far