added generic validation, error handling