Added cleanup option

Added the cleanup option as I suggested in issue #1816