Fixing some bugs, updating some tests and adding documentation