major refactoring work, added javascript unit tests via doctestjs