extracting cleanup method out of existing main() method