builddevice: code overhaul