merge new codes from @dndx