Javascript reorganization