Fleshing out some of the code. Still not entirely sure how this is all structured (python is hardly my mother tongue)