update code to be more compact.  Sync with the frequency version, and make HD