Refactoring and Tests

I did some refactoring and wrote some tests. One is failing, tho (code seems to be wrong)