corrections and optimizing

few bugs and removal of unnecessary measurements.