Implement many of the clearup functions

2 of the tests now pass