fixed possible segfaults