Cleaned up code, tried to put hack-for-loop in it's own function so it wouldn't repeat but then it didn't work so I had to put it back.