Fix data ordering bug from issue 278, and clean up datasets handling