Refactored Code

Refactored code for easy implemetation in COMP2014.