merged stuff from ripn rawdevice