error handling for wrong data format
refactor