Numerous bug fixes, works on simple data set