Refactor - fix looping issue