further improved conversion code