Replace get_or_create() with IntegrityError checks

Since `get_or_create()` is ugly and not really atomic, let's use proper atomic `save()` + `IntegrityError` checking. While at it, some minor fixes as well.