added dynamic validation function