adding validate function