Added Tests, fixed a few bugs