fixed bug in reading from device