add check to stop segfault