Fix two possible exceptions related to the autocompletion, and a tab index error

This PR fixes two errors that can cause exceptions related to autocompletion, and a tab index error.