seemingly debugged version with device identification