resolved segfault, but it's ugly now