Add support for multiple datasets

The current implementation only works with one dataset. 
This PR make it works for an array of datasets.