Did a little refactoring, trying to make loops cleaner