Added some garbage cleanup and removed old horrible loop