Added some unit tests and made the existing code pass them.