seems many duplicated code now between embedded and shared modes. can we reuse them?