midrefactor logic