Fix segfault. Reads and/or write are not working correctly.