Fixed this because it was embarrassing (and written very non pythonic-ly)