Added some regression tests and removed a little duplication.