fixed validation function