Added data verification

Added some basic error handling for invalid data.