refactored javascript as pluggable system, checking in code pending dev testing.