Completed 'clean' function