Fixed bug #18.  Added test cases to make sure this doesn't break again.