made slight changes to ensure proper validation