Fixes validate_required function and adds tests