Refactored and added unit tests. #111.