Measure parsing and some refactoring