reorganization of js code