Refactored: tried to come up with a model layer and an API layer.
Not done yet.