Added tests and made a few changes.