Refactored so code is more OO