added some error checking on the data. fixed #1