fix looping and white space issues