Refactored code and using Mocha for testing