Reorganized code into an object oriented approach and added comments