Refactored Code

Refactored code into a more sensible structure for further expansion