Abstract as much as possible in to a class that doesn't rely on querying the database, to make testing less painful.
Adjustments to satisfy PEP8