General cleanup and dependency fixing