Refactor some logic into the model; document some things