Added some tests, corrected some bugs, cleaned some code.
Added some tests, corrected some bugs, cleaned some code.