Rewrite of data interface, added balanced sampling