javascript refactor and data source