added some error checking in the constructor