Updated method to utilize one loop.