clean up code, thread safety fixes, more nashorn friendly coding style, mozilla_compat