added measurement loop