Refactored code structure to better support autotesting. Added support for karma/jasmine and travis.