updated with validation function