Use extend rather than += (style choice), made some things slightly more pythonic