a little refactoring to simplify readFrames