Refactoring: loop eliminating defined variables moved to its own
function