moving code out to datasource