Extracted block algorithm to separate method

Extracted repeated code to its own method