Fix bug causing one extra slash

Also clean up code a bit.  Tests pass.