Refactoring and improved scripts for measurment