Abstracted python-only stuff into it's own function.