Fixed the segfaults caused when selecting items