Added some more tests and a bit of documentation + refactored code to make it more consistent