Removed unused data structure and tweaked loop conditional