code migrated from dannoz