refactored the code to a major extend by converting most of the class methods to instance methods