Track rewrite4

This is a rewrite of #447 by @pnorman.

This resolves #136 and #446.

This is a rebase of #513/