sanity cleanup of the code and JS bug fix