Fixing missing variable $relation bug