Rewrote some looping