Converted sample code to class & minor fixes.