Added documentation and improved tests