Refactored and set up for testing with Mocha/Chai