Fixing reads before file descriptor is open