fixing a few bugs when tested against a larger data set