Fix bugs, improve formatting, add specs.
Add some tests with PropEr, bugfixes and refactoring.