Refactered method to extract logic to one method.