Added a lot of documentation and tests