fix JS errors and add testing