Add unit testing, update documentation, refactoring.