added more DRY logic