Refactored code, split into seperate classes