Updated with Part-4 Code - with cleanup