Improved tests, started doc and refactoring