Less duplication and prevent segfault