a lot of cleanup and import optimization