Add trash collection and correct some errors