initial import of a working version for refx4