Add more docs, refactor a bit, add more tests