Splitted tab completion handling into multiple functions.
Some cleanup