Add tests to PR #362 and cleanup

This is just a cleanup of @kafunkajunk's PR #362, which was mostly just based on the comments cited by the maintainer @jspahrsummers