Totally refactored code to use classes more