Unit tests for javascript (karma + jasmine).
Move optional fields to the end of the param list.
Slight refactoring to support karma/jasmine/angular unit testing.  Fix a bug
with params.