a lot of cleanup and fixing