Fix #3

The model has been rewritten to be simpler and more efficient. It is also documented.