added proper data validation logic