Refactor javascript to add namespace