Move tab completion into function