added check on data, for better error messaging