Repaired embed mode, some code cleanup