separate code block into functions and calls