This can be DRY-ed up with line 229