Managed to get this to compile, but there's a runtime segfault.