add lock detection, noise, preamble; refactor.