Added a new test, fixed a few bugs