Move the tab-expansion code into its own function.

  This paves the way for further updates.

  Updates issue #47