better patch - without segfaults