Is there a chance that $group doesn't have `user_id` when this is called? If so, use isset(). Same with the next function.