rewrite code in lowlevel