Maybe there is an more concise or elegant way to do this, I just don't know python at all...