pulled out common task logic