untested javascript mode, documented and refactored.