Cleaned up some loops a bit