It looks like lines 91-93 can be replaced with `return ok_flag`.