add initialization checking to prevent segfaults