Fixed #96. It acually worked fine but the test was wrong.

The commit contains several refactors to improve immutability