restructured cleanUp method so that it is more organized and readable