Tests and fix for #25

My suggested changes to fix #25. If you think things should be made differently, I'd be glad to help!