rfactoring and adding requirejs library

refactoring the code to proper javascript classes and functions
bring in requirejs to re-write the tests