changed res logic in main