This commit is largely based on the work from Daniel Dickinson in PR #2096 which was never merged. I tweaked it in a number of ways. All bugs with this package are mine, not his. Signed-off-by: Aaron Curley <accwebs@gmail.com>