Fix segfaults and add stubs.