move stop_before outside as well