Added loop code that works