Simplified the program, but still getting seg faults. It has to do with the buffer.