minor js code reorganization