Moved clean up code